import http from './http'

export interface UserRegisterResponse {
  code: number
  msg: string
  data: {
    user_id: string
    user_email: string
    username: string
    token: string
  }
}

export interface UserLoginResponse {
  code: number
  msg: string
  data: {
    user_email: string
    user_id: string
    username: string
    token: string
  }
}

export interface UserLogoutResponse {
  id: string
  token: string
}

export const registerAPI = async (
  id: string,
  username: string,
  password: string,
): Promise<UserRegisterResponse> => {
  return await http.post('/user/register', { id, username, password })
}

export const loginAPI = async (id: string, password: string): Promise<UserLoginResponse> => {
  return await http.post('/user/login', { id, password })
}

export const logoutAPI = async (id: string, token: string): Promise<UserLogoutResponse> => {
  return await http.post('/user/logout', { id, token })
}
